home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / INTERVIE / GRAPHIC / GEOMOBJS.H < prev    next >
C/C++ Source or Header  |  1991-12-10  |  5KB  |  165 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * Interface to geometrical objects used to implement Graphic primitives.
  25.  */
  26.  
  27. #ifndef geomobjs_h
  28. #define geomobjs_h
  29.  
  30. #include <InterViews/Graphic/persistent.h>
  31.  
  32. class PointObj : public Persistent {
  33. public:
  34.     PointObj(Coord = 0, Coord = 0);
  35.     PointObj(PointObj*);
  36.  
  37.     float Distance(PointObj&);
  38.  
  39.     virtual ClassId GetClassId();
  40.     virtual boolean IsA(ClassId);
  41. protected:
  42.     virtual boolean read(PFile*);
  43.     virtual boolean write(PFile*);
  44. public:
  45.     Coord x, y;
  46. };
  47.  
  48. class LineObj : public Persistent {
  49. public:
  50.     LineObj();
  51.     LineObj(Coord, Coord, Coord, Coord);
  52.     LineObj(LineObj*);
  53.  
  54.     boolean Contains(PointObj&);
  55.     int Same(PointObj& p1, PointObj& p2);
  56.     boolean Intersects(LineObj&);
  57.  
  58.     virtual ClassId GetClassId();
  59.     virtual boolean IsA(ClassId);
  60. protected:
  61.     virtual boolean read(PFile*);
  62.     virtual boolean write(PFile*);
  63. public:
  64.     PointObj p1, p2;
  65. };
  66.  
  67. class BoxObj : public Persistent {
  68. public:
  69.     BoxObj(Coord = 0, Coord = 0, Coord = 0, Coord = 0);
  70.     BoxObj(BoxObj*);
  71.  
  72.     boolean Contains(PointObj&);
  73.     boolean Intersects(BoxObj&);
  74.     boolean Intersects(LineObj&);
  75.     BoxObj operator-(BoxObj&);
  76.     BoxObj operator+(BoxObj&);
  77.     boolean Within(BoxObj&);
  78.  
  79.     virtual ClassId GetClassId();
  80.     virtual boolean IsA(ClassId);
  81. protected:
  82.     virtual boolean read(PFile*);
  83.     virtual boolean write(PFile*);
  84. public:
  85.     Coord left, right;
  86.     Coord bottom, top;
  87. };
  88.  
  89. class MultiLineObj : public Persistent {
  90. public:
  91.     MultiLineObj(Coord* = nil, Coord* = nil, int = 0);
  92.  
  93.     void GetBox(BoxObj& b);
  94.     boolean Contains(PointObj&);
  95.     boolean Intersects(LineObj&);
  96.     boolean Intersects(BoxObj&);
  97.     boolean Within(BoxObj&);
  98.     void SplineToMultiLine(Coord* cpx, Coord* cpy, int cpcount);
  99.     void ClosedSplineToPolygon(Coord* cpx, Coord* cpy, int cpcount);
  100.  
  101.     virtual ClassId GetClassId();
  102.     virtual boolean IsA(ClassId);
  103. protected:
  104.     void GrowBuf();
  105.     boolean CanApproxWithLine(
  106.     double x0, double y0, double x2, double y2, double x3, double y3
  107.     );
  108.     void AddLine(double x0, double y0, double x1, double y1);
  109.     void AddBezierArc(
  110.         double x0, double y0, double x1, double y1,
  111.         double x2, double y2, double x3, double y3
  112.     );
  113.     void CalcSection(
  114.     Coord cminus1x, Coord cminus1y, Coord cx, Coord cy,
  115.     Coord cplus1x, Coord cplus1y, Coord cplus2x, Coord cplus2y
  116.     );
  117.     void CreateMultiLine(Coord* cpx, Coord* cpy, int cpcount);
  118.  
  119.     virtual boolean read(PFile*);
  120.     virtual boolean write(PFile*);
  121. public:
  122.     Coord* x, *y;
  123.     int count;
  124. };
  125.  
  126. class FillPolygonObj : public MultiLineObj {
  127. public:
  128.     FillPolygonObj(Coord* = nil, Coord* = nil, int = 0);
  129.     ~FillPolygonObj();
  130.  
  131.     boolean Contains(PointObj&);
  132.     boolean Intersects(LineObj&);
  133.     boolean Intersects(BoxObj&);
  134.  
  135.     virtual ClassId GetClassId();
  136.     virtual boolean IsA(ClassId);
  137. protected:
  138.     int LowestLeft(Coord*, Coord*, int);
  139.     void Normalize();
  140. protected:
  141.     Coord* normx, *normy;
  142.     int normCount;
  143. };
  144.  
  145. class Extent {
  146. public:
  147.     Extent(float = 0, float = 0, float = 0, float = 0, float = 0);
  148.     Extent(Extent&);
  149.  
  150.     boolean Undefined();
  151.     boolean Within(Extent& e);
  152.     void Merge(Extent&);
  153. public:
  154.     /* defines lower left and center of an object */
  155.     float left, bottom, cx, cy, tol;
  156. };
  157.  
  158. /*
  159.  * inlines
  160.  */
  161.  
  162. inline boolean Extent::Undefined () { return left == cx && bottom == cy; }
  163.  
  164. #endif
  165.